package cn.edu.usst.cs.goldfish.software_engineering.controllers;

import cn.edu.usst.cs.goldfish.software_engineering.entities.Stock;
import cn.edu.usst.cs.goldfish.software_engineering.services.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.List;

@Controller
@RequestMapping("/stock")
public class StockController {

    @Autowired
    private StockService service;

    // 查询所有库存
    @GetMapping
    public String stockList(Model model) {
        // 从服务层获取所有库存数据
        List<Stock> stocks = service.findAll();
        // 将库存数据添加到模型中
        model.addAttribute("stocks", stocks);
        return "stock";  // 返回视图名称
    }

    // 其他方法可以保持不变
    public List<Stock> query() {
        return service.findAll();
    }

    public Stock add(Stock stock) {
        return service.save(stock);
    }
}